import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsPhoneNumber, Length, IsEnum } from 'class-validator';

export enum SmsType {
  LOGIN = 'login',
  REGISTER = 'register',
  RESET_PASSWORD = 'resetPassword',
}

export class LoginDto {
  @ApiProperty({ description: '用户名/手机号' })
  @IsString()
  username: string;

  @ApiProperty({ description: '密码' })
  @IsString()
  @Length(6, 20)
  password: string;
}

export class PhoneLoginDto {
  @ApiProperty({ description: '手机号' })
  @IsPhoneNumber('CN')
  phone: string;

  @ApiProperty({ description: '密码' })
  @IsString()
  @Length(6, 20)
  password: string;
}

export class SmsLoginDto {
  @ApiProperty({ description: '手机号' })
  @IsPhoneNumber('CN')
  phone: string;

  @ApiProperty({ description: '验证码' })
  @IsString()
  @Length(6, 6)
  code: string;
}

export class RegisterDto {
  @ApiProperty({ description: '手机号' })
  @IsPhoneNumber('CN')
  phone: string;

  @ApiProperty({ description: '验证码' })
  @IsString()
  @Length(6, 6)
  code: string;

  @ApiProperty({ description: '密码' })
  @IsString()
  @Length(6, 20)
  password: string;
}

export class ResetPasswordDto {
  @ApiProperty({ description: '手机号' })
  @IsPhoneNumber('CN')
  phone: string;

  @ApiProperty({ description: '验证码' })
  @IsString()
  @Length(6, 6)
  code: string;

  @ApiProperty({ description: '新密码' })
  @IsString()
  @Length(6, 20)
  password: string;
}

export class SendSmsDto {
  @ApiProperty({ description: '手机号' })
  @IsPhoneNumber('CN')
  phone: string;

  @ApiProperty({ description: '验证码类型', enum: SmsType })
  @IsEnum(SmsType)
  type: SmsType;
}
